<template>
	<el-dialog :close-on-click-modal="false" :title="titleMap.show" v-model="visible" :width="500" destroy-on-close @closed="$emit('closed')">
		<el-form :model="form" :rules="rules" :disabled="mode=='show'" ref="dialogForm" label-width="100px" label-position="right">
            <el-row class="elHeight">
                <el-col :span="24">
                    <el-form-item label="审核状态:" prop="auditStatus">
                        <el-radio-group v-model="form.auditStatus" size="small">
                            <el-radio label="1">审核通过</el-radio>
                            <el-radio label="2">审核拒绝</el-radio>
                        </el-radio-group>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row v-if="form.auditStatus == 2">
                <el-col :span="24">
                    <el-form-item label="拒绝原因:" prop="auditRemarks">
                        <el-input type="textarea" :rows="2" v-model="form.auditRemarks" placeholder="请输入拒绝原因" :maxlength="100" show-word-limit />
                    </el-form-item>
                </el-col>
            </el-row>
		</el-form>
		<template #footer>
			<el-button @click="visible=false" >取 消</el-button>
			<el-button v-if="mode!='show'" type="primary" :loading="isSaveing" @click="submit()">确 认</el-button>
		</template>
	</el-dialog>
</template>

<script>
	export default {
		emits: ['success', 'closed'],
        props: {
            url: { type: String, default: () => {return ''} },
        },
		data() {
			return {
				mode: "add",
				titleMap: {
					show: '审核'
				},
				visible: false,
				isSaveing: false,
                form: {
                    id: null,
                    auditStatus: '1',
                    auditRemarks: ""
                },
                rules: {
                    auditStatus: [
                        { required: true, message: '请选择审核意见', trigger: 'blur' },
                    ],
                    auditRemarks: [
                        { required: true, message: '请输入拒绝原因', trigger: 'blur' },
                    ]
                }
			}
		},
		mounted() {
		},
		methods: {
			//显示
			open(title){
				this.visible = true;
                if(title) {
                    this.titleMap.show = title
                }
				return this
			},
			setData(row){
                this.form.id = row.id
			},
			async submit() {
                this.$refs.dialogForm.validate(async (valid) => {
                    if (!valid) {
					    return false;
				    }

                    if (!this.form.auditStatus) {
                        this.$message.error("请选择审核意见");
                        return;
                    }

                    this.isSaveing = true;
                    await this.$API.agent.audit.changeStatus.put(this.form).then(() => {
                        this.visible = false
                        this.$emit('success')
                        this.$notify.success('审核成功')
                    }).finally(() => { this.isSaveing = false; })
                })
			},
		}
	}
</script>

<style scoped>
.elHeight{
	height: 35px;
}
</style>
